<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>canvas画笔效果</title>
    <style>
        *{
            margin:0;
            padding:0;
        }
        html,body,#app{
            width: 100%;
            height: 100%;
            overflow: hidden;
        }
    </style>
</head>
<body>
    <div id="app">
        <canvas ></canvas>
    </div>
    <script>
        let app = document.querySelector('#app');
        app.addEventListener('touchstart', function(e){
            e.preventDefault();
        })
        //获取
        let canvas = document.querySelector('canvas');
        //设置 canvas 画布的宽度和高度
        canvas.width = document.documentElement.clientWidth;
        canvas.height = document.documentElement.clientHeight;
        //通过方法获取画笔对象
        let ctx = canvas.getContext('2d');
        // //移动画笔的起始位置
        // ctx.moveTo(50, 50);
        // //
        // ctx.lineTo(200, 50);
        // //绘制  描边
        // ctx.stroke();

        canvas.addEventListener('touchstart', function(e){
            ctx.strokeStyle = '#58c';
            ctx.lineWidth = 5;
            ctx.moveTo(e.changedTouches[0].clientX, e.changedTouches[0].clientY);
        });
        canvas.addEventListener('touchmove', function(e){
            ctx.lineTo(e.changedTouches[0].clientX, e.changedTouches[0].clientY);
            ctx.stroke();
        });
        canvas.addEventListener('touchend', function(e){

        });
        
    </script>
</body>
</html>